<?php

use yii\db\Migration;

class m180323_025228_create_cards_count extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%cards_count}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'issuser_id' => $this->integer()->defaultValue(0)->comment('发卡人id'),
                'reissuser_id' => $this->integer()->defaultValue(0)->comment('二级发卡人id '),
                'salesman' => $this->integer()->defaultValue(0)->comment('三级用户姓名'),
                'telephone' => $this->integer(11)->defaultValue(0)->comment('三级用户电话'),
                'cards_send_id' => $this->integer()->defaultValue(0)->comment('一级发卡id'),
                'is_withdraw' => $this->smallInteger()->defaultValue(0)->comment('是否为回收卡 0 否 1 是'),
                'batch_id' => $this->integer()->defaultValue(0)->comment('批次id'),
                'number' => $this->smallInteger()->defaultValue(0)->comment('发卡数量'),
                'cardno_begin' => $this->integer()->defaultValue(0)->comment('开始卡号'),
                'cardno_end' => $this->integer()->defaultValue(0)->comment('结束卡号'),
                'proportion' => $this->smallInteger()->defaultValue(0)->comment('分成比例'),
                'status' => $this->smallInteger()->defaultValue(0)->comment('类型 0 一级发卡 1 二级发卡'),
                'created_at' => $this->integer()->defaultValue(0)->comment('发卡时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%cards_count}}');
        }
    }
}
